package cn.sciento.farm.devicemanager.gateway.downlink.service.impl;

import cn.sciento.farm.devicemanager.common.constant.MqttConstant;
import cn.sciento.farm.devicemanager.gateway.downlink.service.MqttCallBackFuture;
import cn.sciento.farm.devicemanager.gateway.model.downlink.AbstractBlockData;
import cn.sciento.farm.devicemanager.gateway.model.downlink.InsectLampConfigData;
import cn.sciento.farm.devicemanager.gateway.model.downlink.InsectLampSwitchData;
import cn.sciento.farm.devicemanager.gateway.model.uplink.InsectLampParam;
import cn.sciento.farm.devicemanager.gateway.model.uplink.InsectLampSwitch;
import cn.sciento.farm.devicemanager.gateway.uplink.service.insectSituationLamp.InsectSituationLampDisposeService;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

@Order(1)
@Service
public class InsectSituationLampDataService implements InsectSituationLampDisposeService {

    @Override
    public void changeSwitch(InsectLampSwitch insectLampSw) {
        MqttCallBackFuture mqttCallBackFuture = MqttCallBackFuture.futurePool.get(
                String.format(
                        MqttConstant.ISM_CONTROL_SWITCH_BLOCK_ID,
                        insectLampSw.getEui()
                )
        );
        if (mqttCallBackFuture != null) {
            AbstractBlockData abstractBlockData = mqttCallBackFuture.getAbstractBlockData();
            if (abstractBlockData instanceof InsectLampSwitchData) {
                InsectLampSwitchData insectLampSwitch= (InsectLampSwitchData)abstractBlockData;
                if (insectLampSwitch.getUpDoorSwitch() != null) {
                    if(insectLampSwitch.getUpDoorSwitch().equals(insectLampSw.getUpDoorSwitch())){
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampSwitch.getLowDoorSwitch() != null) {
                    if(insectLampSwitch.getLowDoorSwitch().equals(insectLampSw.getLowDoorSwitch())){
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampSwitch.getHeatSwitch() != null) {
                    if(insectLampSwitch.getHeatSwitch().equals(insectLampSw.getHeatSwitch())){
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampSwitch.getLighthouseSwitch() != null) {
                    if(insectLampSwitch.getLighthouseSwitch().equals(insectLampSw.getLighthouseSwitch())){
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampSwitch.getSweepSwitch() != null) {
                    if(insectLampSwitch.getUpDoorSwitch().equals(insectLampSw.getUpDoorSwitch())){
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampSwitch.getTileSwitch() != null) {
                    if(insectLampSwitch.getTileSwitch().equals(insectLampSw.getTileSwitch())){
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampSwitch.getPhtotsSwitch() != null) {
                    if(insectLampSwitch.getPhtotsSwitch().equals(insectLampSw.getPhtotsSwitch())){
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampSwitch.getTimeSwitch() != null) {
                    if(insectLampSwitch.getTimeSwitch().equals(insectLampSw.getTimeSwitch())){
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampSwitch.getLighthouseSwitch() != null) {
                    if(insectLampSwitch.getLighthouseSwitch().equals(insectLampSw.getLighthouseSwitch())){
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampSwitch.getStatusRefresh() != null) {
                    if(insectLampSwitch.getStatusRefresh().equals(insectLampSw.getStatusRefresh())){
                        mqttCallBackFuture.setResponse("");
                    }
                }
            } else {
                mqttCallBackFuture.setResponse("");
            }
        }
    }

    @Override
    public void changeParam(InsectLampParam insectLampParam) {
        MqttCallBackFuture mqttCallBackFuture = MqttCallBackFuture.futurePool.get(
                String.format(
                        MqttConstant.ISM_CONTROL_PARAM_BLOCK_ID,
                        insectLampParam.getEui()
                )
        );
        if (mqttCallBackFuture != null) {
            AbstractBlockData abstractBlockData = mqttCallBackFuture.getAbstractBlockData();
            if (abstractBlockData instanceof InsectLampConfigData) {
                InsectLampConfigData insectLampConfig= (InsectLampConfigData)abstractBlockData;
                if (insectLampConfig.getLinghtControlTime() != null) {
                    if (insectLampConfig.getLinghtControlTime().equals(insectLampParam.getLinghtControlTime())) {
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampConfig.getStartControlTime() != null) {
                    if (insectLampConfig.getStartControlTime().equals(insectLampParam.getStartControlTime())) {
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampConfig.getEndControlTime() != null) {
                    if (insectLampConfig.getEndControlTime().equals(insectLampParam.getEndControlTime())) {
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampConfig.getCollectTime() != null) {
                    if (insectLampConfig.getCollectTime().equals(insectLampParam.getCollectTime())) {
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampConfig.getHeatTimeSet() != null) {
                    if (insectLampConfig.getHeatTimeSet().equals(insectLampParam.getHeatTimeSet())) {
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampConfig.getHeatTemperatureSet() != null) {
                    if (insectLampConfig.getHeatTemperatureSet().equals(insectLampParam.getHeatTemperatureSet())) {
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampConfig.getDataPeriod() != null) {
                    if (insectLampConfig.getDataPeriod().equals(insectLampParam.getDataPeriod())) {
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampConfig.getPhtotsPeriod() != null) {
                    if (insectLampConfig.getPhtotsPeriod().equals(insectLampParam.getPhtotsPeriod())) {
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampConfig.getRatio() != null) {
                    if (insectLampConfig.getRatio().equals(insectLampParam.getRatio())) {
                        mqttCallBackFuture.setResponse("");
                    }
                }
                if (insectLampConfig.getParamRefresh() != null) {
                    if (insectLampConfig.getParamRefresh().equals(insectLampParam.getParamRefresh())) {
                        mqttCallBackFuture.setResponse("");
                    }
                }
            } else {
                mqttCallBackFuture.setResponse("");
            }
        }
    }
}
